const { VITE_APP_OIDC_APPID, VITE_APP_OIDC_REDIRACT, VITE_APP_OIDC_URL } =
  import.meta.env;
import { getTimestamp } from "@/utils/index.js";
export function zeroTrustLogin({
  id,
  serverUrl = `${VITE_APP_OIDC_URL}/frontend/login`,
  redirectUrl = encodeURIComponent(VITE_APP_OIDC_REDIRACT),
  appId = VITE_APP_OIDC_APPID,
  height = 400,
  width = 365,
  tip = "",
}) {
  return new Promise(function (resolve, reject) {
    const loginBox = document.createElement("div");
    loginBox.id = id;
    const tipBox = document.createElement("span");
    tipBox.id = "tipspan";
    tipBox.innerHTML = tip;
    document.getElementById("pane-qrcode").appendChild(loginBox);
    const iframe = document.createElement("iframe");
    const url = `${serverUrl}${
      appId ? `?appId=${appId}&time=${getTimestamp()}` : ""
    }`;
    iframe.src = url;
    iframe.width = `${width}px`;
    iframe.height = `${height}px`;

    const ele = document.getElementById(id);
    ele.innerHTML = "";
    ele.appendChild(iframe);
    resolve();
  });
}

export function removeScipt(_id) {
  const dom = document.getElementById(_id);
  console.log(dom);
  if (dom) {
    dom.parentNode.removeChild(dom);
  }
}
